home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 120 / CD Gamer Issue 120 (March 2003) (Disc 2).ISO / mods / Q2_Codered / codeRED1_0.exe / Data1.cab / r_model.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-07  |  5.4 KB  |  253 lines

  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20.  
  21. /*
  22.  
  23. d*_t structures are on-disk representations
  24. m*_t structures are in-memory
  25.  
  26. */
  27.  
  28. /*
  29. ==============================================================================
  30.  
  31. BRUSH MODELS
  32.  
  33. ==============================================================================
  34. */
  35.  
  36.  
  37. //
  38. // in memory representation
  39. //
  40. // !!! if this is changed, it must be changed in asm_draw.h too !!!
  41. typedef struct
  42. {
  43.     vec3_t        position;
  44. } mvertex_t;
  45.  
  46. typedef struct
  47. {
  48.     vec3_t        mins, maxs;
  49.     float        radius;
  50.     int            headnode;
  51.     int            visleafs;        // not including the solid leaf 0
  52.     int            firstface, numfaces;
  53. } mmodel_t;
  54.  
  55.  
  56. #define    SIDE_FRONT    0
  57. #define    SIDE_BACK    1
  58. #define    SIDE_ON        2
  59.  
  60.  
  61. #define    SURF_PLANEBACK        1
  62. #define SURF_DRAWTURB        2
  63.  
  64. #define SurfaceIsTranslucent(surf) ((surf)->texinfo->flags & (SURF_TRANS33|SURF_TRANS66))
  65. #define SurfaceIsAlphaBlended(surf) ((surf)->texinfo->flags & SURF_TRANS33 && (surf)->texinfo->flags & SURF_TRANS66)
  66. #define SurfaceHasNoLightmap(surf) ((surf)->texinfo->flags & (SURF_SKY|SURF_TRANS33|SURF_TRANS66|SURF_WARP) && !SurfaceIsAlphaBlended((surf)))
  67.  
  68. // !!! if this is changed, it must be changed in asm_draw.h too !!!
  69. typedef struct
  70. {
  71.     unsigned short    v[2];
  72. } medge_t;
  73.  
  74. typedef struct mtexinfo_s
  75. {
  76.     float        vecs[2][4];
  77.     int            flags;
  78.     int            numframes;
  79.     struct mtexinfo_s    *next;        // animation chain
  80.     image_t        *image;
  81. } mtexinfo_t;
  82.  
  83. #define    VERTEXSIZE    7
  84.  
  85. typedef struct glpoly_s
  86. {
  87.     struct    glpoly_s    *next;
  88.     int        numverts;
  89.     float    verts[4][VERTEXSIZE];    // variable sized (xyz s1t1 s2t2)
  90. } glpoly_t;
  91.  
  92. typedef struct msurface_s
  93. {
  94.     int            visframe;        // should be drawn when node is crossed
  95.  
  96.     cplane_t    *plane;
  97.     int            flags;
  98.  
  99.     int            firstedge;    // look up in model->surfedges[], negative numbers
  100.     int            numedges;    // are backwards edges
  101.     
  102.     short        texturemins[2];
  103.     short        extents[2];
  104.  
  105.     int            light_s, light_t;    // gl lightmap coordinates
  106.     int            dlight_s, dlight_t; // gl lightmap coordinates for dynamic lightmaps
  107.  
  108.     glpoly_t    *polys;                // multiple if warped
  109.     struct    msurface_s    *texturechain;
  110.     struct  msurface_s    *lightmapchain;
  111.  
  112.     mtexinfo_t    *texinfo;
  113.     
  114. // lighting info
  115.     int            dlightframe;
  116.     int            dlightbits;
  117.  
  118.     int            lightmaptexturenum;
  119.     byte        styles[MAXLIGHTMAPS];
  120.     float        cached_light[MAXLIGHTMAPS];    // values currently used in lightmap
  121.     byte        *samples;        // [numstyles*surfsize]
  122.     byte        *stainsamples;
  123. } msurface_t;
  124.  
  125. typedef struct mnode_s
  126. {
  127. // common with leaf
  128.     int            contents;        // -1, to differentiate from leafs
  129.     int            visframe;        // node needs to be traversed if current
  130.     
  131.     float        minmaxs[6];        // for bounding box culling
  132.  
  133.     struct mnode_s    *parent;
  134.  
  135. // node specific
  136.     cplane_t    *plane;
  137.     struct mnode_s    *children[2];    
  138.  
  139.     unsigned short        firstsurface;
  140.     unsigned short        numsurfaces;
  141. } mnode_t;
  142.  
  143.  
  144.  
  145. typedef struct mleaf_s
  146. {
  147. // common with node
  148.     int            contents;        // wil be a negative contents number
  149.     int            visframe;        // node needs to be traversed if current
  150.  
  151.     float        minmaxs[6];        // for bounding box culling
  152.  
  153.     struct mnode_s    *parent;
  154.  
  155. // leaf specific
  156.     int            cluster;
  157.     int            area;
  158.  
  159.     msurface_t    **firstmarksurface;
  160.     int            nummarksurfaces;
  161. } mleaf_t;
  162.  
  163.  
  164. //===================================================================
  165.  
  166. //
  167. // Whole model
  168. //
  169.  
  170. typedef enum {mod_bad, mod_brush, mod_sprite, mod_alias } modtype_t;
  171.  
  172. typedef struct model_s
  173. {
  174.     char        name[MAX_QPATH];
  175.  
  176.     int            registration_sequence;
  177.  
  178.     modtype_t    type;
  179.     int            numframes;
  180.     
  181.     int            flags;
  182.  
  183. //
  184. // volume occupied by the model graphics
  185. //        
  186.     vec3_t        mins, maxs;
  187.     float        radius;
  188.  
  189. //
  190. // brush model
  191. //
  192.     int            firstmodelsurface, nummodelsurfaces;
  193.  
  194.     int            numsubmodels;
  195.     mmodel_t    *submodels;
  196.  
  197.     int            numplanes;
  198.     cplane_t    *planes;
  199.  
  200.     int            numleafs;        // number of visible leafs, not counting 0
  201.     mleaf_t        *leafs;
  202.  
  203.     int            numvertexes;
  204.     mvertex_t    *vertexes;
  205.  
  206.     int            numedges;
  207.     medge_t        *edges;
  208.  
  209.     int            numnodes;
  210.     int            firstnode;
  211.     mnode_t        *nodes;
  212.  
  213.     int            numtexinfo;
  214.     mtexinfo_t    *texinfo;
  215.  
  216.     int            numsurfaces;
  217.     msurface_t    *surfaces;
  218.  
  219.     int            numsurfedges;
  220.     int            *surfedges;
  221.  
  222.     int            nummarksurfaces;
  223.     msurface_t    **marksurfaces;
  224.  
  225.     dvis_t        *vis;
  226.  
  227.     byte        *lightdata;
  228.  
  229.     // for alias models and skins
  230.     image_t        *skins[MAX_MD2SKINS];
  231.  
  232.     int            extradatasize;
  233.     void        *extradata;
  234. } model_t;
  235.  
  236. //============================================================================
  237.  
  238. void    Mod_Init (void);
  239. void    Mod_ClearAll (void);
  240. model_t *Mod_ForName (char *name, qboolean crash);
  241. mleaf_t *Mod_PointInLeaf (float *p, model_t *model);
  242. byte    *Mod_ClusterPVS (int cluster, model_t *model);
  243.  
  244. void    Mod_Modellist_f (void);
  245.  
  246. void    *Hunk_Begin (int maxsize);
  247. void    *Hunk_Alloc (int size);
  248. int        Hunk_End (void);
  249. void    Hunk_Free (void *base);
  250.  
  251. void    Mod_FreeAll (void);
  252. void    Mod_Free (model_t *mod);
  253.